<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    <%@taglib uri="/authUtil"  prefix="authUtil"%>
    <%@taglib uri="/adminUtil"  prefix="adminUtil"%>
	<c:if test="${empty requestScope.adminList }">
		<center><h1>没有人员信息</h1></center>
	</c:if>
	<c:if test="${!empty requestScope.adminList }">
		<!-- 资源管理模块 -->
        <div role="tabpanel" class="tab-pane active" id="sour">
        	<div class="check-div form-inline">
            	<button class="btn btn-yellow btn-xs" data-toggle="modal" data-target="#addDiv" id="addButton">添加人员</button>
            </div>
           	<div class="data-div">
                <div class="row tableHeader">
                	<div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 ">
                    	用户名
                    </div>
                    <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1">
                        姓名
                    </div>
                    <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1">
                        用户身份
                    </div>
                    <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1">
                         人力管理权限
                    </div>
					<div class="col-lg-1 col-md-1 col-sm-1 col-xs-1">
                          房型管理权限
                    </div>
					<div class="col-lg-1 col-md-1 col-sm-1 col-xs-1">
                          房间管理权限
                    </div>
					<div class="col-lg-1 col-md-1 col-sm-1 col-xs-1">
                          入住管理权限
                    </div>
					<div class="col-lg-1 col-md-1 col-sm-1 col-xs-1">
                          换房管理权限
                    </div>
					<div class="col-lg-1 col-md-1 col-sm-1 col-xs-1">
                          续住管理权限
                    </div>
					<div class="col-lg-1 col-md-1 col-sm-1 col-xs-1">
                          财务管理权限
                    </div>
					<div class="col-lg-1 col-md-1 col-sm-1 col-xs-1">
                          注册日期
                    </div>
					<div class="col-lg-1 col-md-1 col-sm-1 col-xs-1">
                          操作
                    </div>
                  </div>
                  <div class="tablebody">
                 	<c:forEach items="${requestScope.adminList }" var="admin">
	                  	<div id="collapseAccount" class="collapse in" aria-expanded="true">
	                    	<div class="row">
	                        	<div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 levl1 ">${ admin.username}
	                            </div>
	                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 levl1 ">${admin.name }
	                            </div>
	                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 levl1 ">${adminUtil:getAdminRole(admin.roleCode) }
	                            </div>
	                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 levl1 ">
		                            <c:if test="${authUtil:isAuth(admin.auth,0) }">
										√
									</c:if>
	                            </div>
	                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 levl1 ">
		                            <c:if test="${authUtil:isAuth(admin.auth,1) }">
										√
									</c:if>
	                            </div>
	                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 levl3 ">
		                            <c:if test="${authUtil:isAuth(admin.auth,2) }">
										√
									</c:if>
	                            </div>
	                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 levl3 ">
		                            <c:if test="${authUtil:isAuth(admin.auth,3) }">
										√
									</c:if>
	                            </div>
	                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 levl3 ">
		                            <c:if test="${authUtil:isAuth(admin.auth,4) }">
										√
									</c:if>
	                            </div>
	                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 levl3 ">
		                            <c:if test="${authUtil:isAuth(admin.auth,5) }">
										√
									</c:if>
	                            </div>
	                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 levl3 ">
		                            <c:if test="${authUtil:isAuth(admin.auth,6) }">
										√
									</c:if>
	                            </div>
	                           	<div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 levl3 ">
	                           		${admin.regDate }
	                            </div>
	                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1">
	                               	<button class="btn btn-success btn-xs" data-toggle="modal" data-target="#addDiv" onclick='changeButtonFun(${admin.id})'>修改</button>
	                               	<button class="btn btn-danger btn-xs" data-toggle="modal" data-target="" onclick='deleteButtonFun(${admin.id})'>删除</button>
	                            </div>
	                         </div>
	                      </div>
                      </c:forEach>
                   </div>
                   
				</div>
			</div>
		</c:if>
			<!--页码块-->
			<center>
				<a class="btn btn-xs btn-xs btn-green" onclick='jump("/hotel/admin/mainMenu?page=1")'>#首页
				</a>
				<a class="btn btn-xs btn-xs btn-green" onclick='jump("/hotel/admin/mainMenu?page=${currentPage==1?1:currentPage-1}")'>&lt;上一页
				</a>
				<a class="btn btn-xs btn-xs btn-green" onclick='jump("/hotel/admin/mainMenu?page=${currentPage+1}")'>下一页&gt;
				</a>
			</center>
	
	
	<!-- 添加用户菜单 -->
	<div class="modal fade" id="addDiv" role="dialog" aria-labelledby="gridSystemModalLabel">
    	<div class="modal-dialog" role="document">
    		<input type="hidden" id="adminId">
        	<div class="modal-content">
            	<div class="modal-header">
                	<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    	<h4 class="modal-title" id="gridSystemModalLabel">添加管理员</h4>
                </div>
                <div class="modal-body">
                	<div class="container-fluid">
                    	<div class="form-horizontal">
                        	<div class="form-group ">
                            	<label for="username" class="col-xs-3 control-label">用户名：</label>
                                	<div class="col-xs-8 ">
                                    	<input type="text" class="form-control input-sm duiqi" id="username" placeholder="">
                                	</div>
                           </div>
		               		<div class="form-group">
		                    	<label for="password" class="col-xs-3 control-label">密码：</label>
		                    	<div class="col-xs-8 ">
		                        	<input type="password" class="form-control input-sm duiqi" id="password" placeholder="">
		                   		</div>
		                    </div>
		                    <div class="form-group">
		                    	<label for="rePassword" class="col-xs-3 control-label">重复密码：</label>
		                    	<div class="col-xs-8 ">
		                        	<input type="password" class="form-control input-sm duiqi" id="rePassword" placeholder="">
		                   		</div>
		                    </div>
		                    <div class="form-group">
		                    	<label for="name" class="col-xs-3 control-label">姓名：</label>
		                        <div class="col-xs-8">
		                        	<input type="text" class="form-control input-sm duiqi" id="name" placeholder="">
		                        </div>
		                    </div>
		                    <div class="form-group">
		                    	<label for="roleCode" class="col-xs-3 control-label">身份选择：</label>
		                        <div class="col-xs-8">
		                        	<select id="roleCode" onchange="setAuth()">
										<option value=0>人力管理</option>
										<option value=1>房间管理</option>
										<option value=2>前台</option>
										<option value=3>财务管理</option>
									</select>
		                    	</div>
		                    </div>
		                    
		                    <div class="form-group">
		                    	<label for="exampleInput1" class="col-xs-3 control-label">附加权限：</label>
		                    	<div class="col-xs-8">
		                    	<input id="auth" type="checkbox" value="0" disabled checked>用户数据管理<br>
								<input id="auth" type="checkbox" value="1">房间类型管理<br>
								<input id="auth" type="checkbox" value="2">房间数据管理<br>
								<input id="auth" type="checkbox" value="3">入住信息管理<br>
								<input id="auth" type="checkbox" value="4">换房信息管理<br>
								<input id="auth" type="checkbox" value="5">续住信息管理<br>
								<input id="auth" type="checkbox" value="6">财务信息管理<br>
		                        </div>
		                    </div>
		                    <div class="form-group">
		                    	<label for="name" class="col-xs-3 control-label">备注：</label>
		                        <div class="col-xs-8">
		                        	<textarea cols="15" rows="10" class="form-control input-sm duiqi" id="zcomment"></textarea><br>
		                        </div>
		                    </div>
               			 </div>
                      </div>
                  </div>
                  <div class="modal-footer">
                  	<button type="button" class="btn btn-xs btn-xs btn-white" data-dismiss="modal">取 消</button>
                  	<button type="button" class="btn btn-xs btn-xs btn-green" id="submit">提交</button>
                  	<button type="button" class="btn btn-xs btn-xs btn-green" id="change">修改</button>
				</div>
			</div>
		</div>
	</div>
	
	<style>
		#add{
			display:none;
		}
		#change{
			display:none;
		}
	</style>
	<script src="/hotel/js/jquery.min.js"></script>
	<script src="/hotel/js/jumpUtil.js"></script>
	<script type="text/javascript">
		function clearContent(){
			$('#username').val('')
			document.getElementById('password').disabled=false;
			document.getElementById('rePassword').disabled=false;
			$('#name').val('')
			$('#roleCode').val(0)
			setRoleAuth(0)
			$('#zcomment').text('');
		}
		function setRoleAuth(code){
			v1=new Array(1,0,0,0,0,0,0);v2=new Array(0,1,1,0,0,0,0);v3=new Array(0,0,0,1,1,1,0);v4=new Array(0,0,0,0,0,0,1)
			arrays=new Array(v1,v2,v3,v4)
			//alert(arrays[1][0])
			auths=$("input[type='checkbox']")
			for(var i=0;i<auths.length;i++){
				//alert(i)
				if(arrays[code][i]==1){
					auths[i].disabled=true
					auths[i].checked=true
				}else{
					auths[i].disabled=false
					auths[i].checked=false
				}
			}
		}
		function setAuth(){
			//alert("test")
			code=$("#roleCode").val()
			setRoleAuth(code)
			//alert(auth[0].value)
		}
		function changeButtonFun(id){
			$('#gridSystemModalLabel').text('修改管理员')
			//var add=document.getElementById('add')
			//add.style.display='block'
			var change=document.getElementById('change')
			change.style.display='inline'
			var submit=document.getElementById('submit')
			submit.style.display='none'
			$.get("/hotel/admin/getAdminInfor?id="+id,{},function(res){
				var ad=eval('(' +res + ')').object
				//alert(ad.username)
				$('#adminId').val(ad.id)
				$('#username').val(ad.username)
				document.getElementById('password').disabled=true;
				document.getElementById('rePassword').disabled=true;
				$('#name').val(ad.name)
				$('#roleCode').val(ad.roleCode)
				auths=$("input[type='checkbox']")
				authNum=ad.auth
				//alert(authNum)
				setRoleAuth(ad.roleCode)
				for(var i=0;i<auths.length;i++){
					auths[i].checked=((authNum>>i&1)==1)
					//alert(authNum)
					//authNum/=2
				}
				//
				$('#zcomment').text(ad.zcomment);
				
				//$('#password').disabled=true;
			})
		}
		$("#addButton").click(function(){
			$('#gridSystemModalLabel').text('添加管理员')
			clearContent()
			//var add=document.getElementById('add')
			//add.style.display='block'
			var change=document.getElementById('change')
			change.style.display='none'
			var submit=document.getElementById('submit')
			submit.style.display='inline'
		})
		$("#cancel").click(function(){
			var add=document.getElementById('add')
			add.style.display='none'
			clearContent()
		})
		$("#submit").click(function(){
			checks=$("input[type='checkbox']:checked")
			auth=0
			for(var i=0;i<checks.length;i++){
				auth|=1<<checks[i].value
			}
			p1=$("#password").val();p2=$("#rePassword").val()
			if(p1!=p2){
				alert("密码两次输入不一致！")
				return ;
			}
			data={"username":$("#username").val(),"password":p1,"name":$("#name").val(),
					"roleCode":$("#roleCode").val(),"auth":auth,"zcomment":$("#zcomment").val()
			}
			$.post("/hotel/admin/addNewAdmin.do",data,function(str){
				var res=eval('(' +str + ')')
				//alert(res.message);
				if(res.code==0){
					window.location.href="/hotel/system/mainPage"
				}else{
					alert(res.message);
				}
			});
			return ;
		})
		$("#change").click(function(){
			checks=$("input[type='checkbox']:checked")
			auth=0
			for(var i=0;i<checks.length;i++){
				auth|=1<<checks[i].value
			}
			p1=$("#password").val();p2=$("#rePassword").val()
			if(p1!=p2){
				alert("密码两次输入不一致！")
				return ;
			}
			data={"id":$("#adminId").val(),"username":$("#username").val(),"name":$("#name").val(),
					"roleCode":$("#roleCode").val(),"auth":auth,"zcomment":$("#zcomment").val()
			}
			//alert(JSON.stringify(data))
			$.post("/hotel/admin//changeAdminInfor.do",data,function(str){
				var res=eval('(' +str + ')')
				//alert(res.message);
				if(res.code==0){
					window.location.href="/hotel/system/mainPage"
				}else{
					alert(res.message);
				}
			});
			return ;
		})
		function deleteButtonFun(id){
			if(confirm("您确定要删除该用户吗？")){
				$.post("/hotel/admin/deleteAdmin.do",{"id":id},function(str){
					var res=eval('(' +str + ')')
					//alert(res.message);
					if(res.code==0){
						window.location.href="/hotel/system/mainPage"
					}else{
						alert(res.message);
					}
				});
			}
		}
	</script>
</html>